package phoenix.mob_android.test_objects;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.TestBaseMobAndroidExt;
import phoenix.mob_android.test_objects.data_providers.SearchDataProviders;

public class SearchTests extends TestBaseMobAndroidExt
{
	public SearchTests(PhoenixManager p_phoenix)
	{
		super(p_phoenix);
	}

	// Data
	public SearchDataProviders dataProviders = new SearchDataProviders(manager);

	public void searchTest()
	{
		try
		{
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().isOnSearchPage();
			page().searchPage().clickGridButton().isOnGridSearchPage().clickMapButton().isOnMapSearchPage().clickSingleButton
					().isOnSearchPage();
			page().searchPage().openSearchParameters().chooseGender("male").submitSearchParameters().checkForSearchResults();
			page().searchPage().openSearchParameters().chooseGender("female").submitSearchParameters().checkForSearchResults();
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Search test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void searchActionsTest()
	{
		try
		{
			if (page().searchPage().isOnSearchPage())
			{
				page().searchPage().openPrivateChat();
				page().chatPage().isOnPrivateChatPage();
				page().mainMenu().openMainMenu().openSearch();
				page().searchPage().makeWinkFromSearch();
				if (page().searchPage().isWinkSend().equals("true"))
				{
					log().errorAndScreen("Wink doesn't send from search page");
				}
				page().searchPage().addToFavouriteFromSearch();
				String p_screennameFromSearch = page().searchPage().getScreennameOfUser();
				page().mainMenu().openMainMenu().openFavourites();
				if (!page().favouritesPage().checkForFriends())
				{
					log().errorAndScreen("User doesn't added to favourites");
				}
				if (manager.isFlirt() || manager.isCL())
				{
					String p_screennameFromFavourites = page().favouritesPage().getScreennameOfFriend();
					if (!(p_screennameFromSearch.equals(p_screennameFromFavourites)))
					{
						log().errorAndScreen(
								"User added from search => " + p_screennameFromSearch + " doesn't equals user from favourites => " +
										p_screennameFromFavourites);
					}
				}
				page().favouritesPage().openProfile().removeFromFavourites();
				page().mainMenu().openMainMenu().openFavourites();
				if (page().favouritesPage().checkForFriends())
				{
					log().errorAndScreen("User doesn't remove from favourites");
				}
			}
			else
			{
				log().errorAndScreen("Not on Search page");
			}
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Search action test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void checkForBannersInSearchAfterPay()
	{
		try
		{
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickSingleButton();
			page().searchPage().isOnSearchPage();
			page().searchPage().scrollDownAndCheckForUpgradeButton(20);
			page().mainMenu().openMainMenu().openActivity().openMainMenu().openSearch();
			page().searchPage().clickGridButton();
			page().searchPage().isOnGridSearchPage().scrollDownAndCheckForUpgradeButton(6);
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Check for banners in search after pay error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void redirectPPSearchPageListTest()
	{
		try
		{
			md().wait(5);
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickSingleButton();
			page().searchPage().scrollDownSearch().clickUpgradeButton();
			page().paymentPage().isOnPaymentPage();
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Redirect PP search page list test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void redirectPPSearchPageGridTest()
	{
		try
		{
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickGridButton().scrollDownSearch().clickUpgradeButton();
			page().paymentPage().isOnPaymentPage();
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Redirect PP search page grid test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}
}
